<?php

namespace App\Admin\Controllers;

use App\BaiduProject;
use App\Project;
use App\User;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class HrefController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '表单链接生成';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new BaiduProject());
        $grid->column('id', __('Id'));
        $grid->column('project.name', __('项目'));
        $grid->column('href1', __('百度api链接'))->display(function ($value){
            return route('baidu',['project_id'=>$this->project_id,'create_user_id'=>$this->user_id]);
        })->copyable();
        $grid->column('href4', __('快手api链接'))->display(function ($value){
            return route('kuaishou',['project_id'=>$this->project_id,'create_user_id'=>$this->user_id]);
        })->copyable();
        $grid->column('href3', __('华为api链接'))->display(function ($value){
            return route('huawei',['project_id'=>$this->project_id,'create_user_id'=>$this->user_id]);
        })->copyable();;
        $grid->column('href5', __('头条'))->display(function ($value){
            return route('toutiao',['project_id'=>$this->project_id,'create_user_id'=>$this->user_id]);
        })->copyable();;
        $grid->column('href2', __('腾讯api链接'))->display(function ($value){
            return route('tengxun',['project_user'=>$this->project_id.'_'.$this->user_id]);
        })->copyable();;
        $grid->column('user.realname', __('负责人'));
        $grid->column('created_at', __('创建时间'));
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(BaiduProject::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('project_id', __('Project id'));
        $show->field('user_id', __('User id'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new BaiduProject());

        $form->select('project_id', __('项目'))->options(Project::getSelectOptions());
        $form->select('user_id', __('人员'))->options(User::getSelectOptions());

        return $form;
    }
}
